package cur.nature.framework.mvc.crud;

import cur.nature.framework.mvc.base.BaseController;

public abstract class  CrudController<S extends CrudService> implements BaseController {
    protected S baseService;
    public CrudController(S baseService) {
        this.baseService = baseService;
    }

    public S getService() {
        return baseService;
    }



//    public Class<T> getTClass(int paramPos) {
//        Class<T> tClass = (Class<T>)((ParameterizedType)getClass().getGenericSuperclass()).getActualTypeArguments()[paramPos];
//        return tClass;
//    }
//
//    public T transform(V param){
//        T entity = JsonUtil.parseObject(JsonUtil.toJSONString(param), getTClass(0));
//        return entity;
//    }

//    @Operation(summary = "保存基类")
//    @ApiResponse(responseCode = "200", description = "foo")
//    @PostMapping("/save")
//    public  BaseAPI.SaveResult<V> save(@Valid @RequestBody V param){
//        T entity = transform(param);
//        int rows = this.baseService.save(entity);
//        BaseAPI.SaveResult<V> result = new BaseAPI.SaveResult();
//        //设置id
//        if(param.getId() == null || param.getId() == 0){
//            param.setId(entity.getId());
//        }
//        result.setRows(rows);
//        result.setObject(rows==0?null:param);
//        return result;
//    }
//
//    @Operation(summary = "根据ID列表删除基类")
//    @ApiResponse(responseCode = "200", description = "foo")
////    @ApiResponses(value = { @ApiResponse(code = 200, message = "Success", response = BaseAPI.DeleteResult.class) })
//    @PostMapping("/deleteByIdList")
//    public BaseAPI.DeleteResult deleteByIdList(@Valid @RequestBody BaseAPI.DeleteParam param){
//        int save = this.baseService.deleteByIdList(param.getIdList());
//        BaseAPI.DeleteResult result = new BaseAPI.DeleteResult();
//        result.setRows(save);
//        return result;
//    }


//    public static void main(String[] args) {
//        CrudController<BaseModel,Integer> foo = new CrudController<BaseModel,Integer>(null){};
//        System.out.println(foo.getTClass(1));
//    }
}
